﻿using System;
namespace Colors.Xroad.Eu.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="CanMix", Namespace="http://colors.x-road.eu/", Target=typeof(CanMix))]
    public class CanMixSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected CanMix clazz;
        
        public CanMixSerializer(CanMix clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Color");
            if (clazz.Color!=null) {
                Writer.WriteString(clazz.Color.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Color");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Color") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>CanMix>Color");
                }
                clazz.Color = new global::Colors.Xroad.Eu.Color(Reader.ReadElementString("Color"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>CanMix>Color", Reader.LocalName);
            }
        }
    }
}
